
Page({

  /**
   * 页面的初始数据
   */
  data: {
    schema:[
      {
        label:'视频裁剪的最小长度',
        prop:'minDuration',
        type:'number'
      },
      {
        label:'视频裁剪的最大长度',
        prop:'maxDuration',
        type:'number'
      },
    ],
    formData:{
      minDuration: 0,
      maxDuration: 10
    },
    title: '',
    result: '',
    remark: '',
    webUrl: ''
  },
  onLoad(options) {
    console.log('options', options)
    wx.setNavigationBarTitle({
      title: options.title,
    })
    
    this.setData({
      title: options.title,
      zh:options.zh,
      remark: options.remark,
      webUrl: options.webUrl
    })
  },
  getFormData(e) {
    const formData = {}
    this.data.schema.forEach(item => {
      if(item.type === 'number') {
        if(!isNaN(+e.detail.formData[item.prop]) && e.detail.formData[item.prop] !== '') {
          formData[item.prop] = +e.detail.formData[item.prop]
        }
      } else {
        formData[item.prop] = e.detail.formData[item.prop]
      }
    })
    this.setData({
      formData: formData
    })
  },
  choose1() {
    const that = this;
    wx.chooseMedia({
      count: 1,
      mediaType: ['video'],
      sourceType: ['camera', 'album'],
      success(res) {
        console.log(res);
        if(res.errMsg === 'chooseMedia:ok') {
            const tempFile = res.tempFiles[0]
            wx.showModal({
              title: '获取本地临时文件路径成功,点击确定打开视频编辑器',
              content: tempFile.tempFilePath,
              showCancel: false,
              complete: (res) => {
                if (res.confirm) {
                  wx.openVideoEditor({
                    filePath: tempFile.tempFilePath,
                    minDuration: 10,
                    maxDuration: 20,
                    success (res) {
                      that.setData({
                        result: res
                      })
                    },
                    fail(err) {
                      that.setData({
                        result: err
                      })
                    }
                  })
                }
              }
            })
        } else {
          wx.showModal({
            title: '从相册或相机中选择视频，获取临时文件路径失败',
            content: res,
            showCancel: false
          })
        }
      },
      fail(err) {
        wx.showModal({
          title: '从相册或相机中选择视频，获取临时文件路径失败',
          content: err,
          showCancel: false
        })
      }
    })
  },
  onUnload() {
  }
})